package com.kerrykidz.system.util.sync;

import java.util.List;

import org.quartz.JobExecutionContext;

public abstract class DataSyncTask extends AbstractSyncTask {

	private TaskCycle cycle;

	public DataSyncTask(TaskCycle cycle) {
		this.cycle = cycle;
	}

	public DataSyncTask() {

	}

	@Override
	protected List<SyncBean> checkCycleTask(JobExecutionContext context) {
		List<SyncBean> syncs;

		boolean isEveryday = cycle == TaskCycle.EVERY_DAY;

		if (!isEveryday)
			syncs = SqlHelper.CONSTANTLY;
		else
			syncs = SqlHelper.EVERY_DAY;

		for (SyncBean sync : syncs) {
			if (SyncParamHelper.CURRENT_STORE.equals(SyncParamHelper.ZONGBU)) {
				if (sync.getSyncType() == SyncBean.SYNCTYPE_MD)
					continue;
			} else {
				if (sync.getSyncType() == SyncBean.SYNCTYPE_ZB)
					continue;
			}
			SqlHelper.checkIntervalTaskDate(sync, context.getFireTime(), isEveryday);
		}

		return syncs;
	}

	public void setCycle(TaskCycle cycle) {
		this.cycle = cycle;
	}

	enum TaskCycle {
		/**
		 * 每天执行一次
		 */
		EVERY_DAY,
		/**
		 * 实时的任务(其实也不是那么实时。。。 O . O)
		 */
		CONSTANTLY
	}
}
